home *** CD-ROM | disk | FTP | other *** search
/ Total Network Tools 2002 / NextStepPublishing-TotalNetworkTools2002-Win95.iso / Archive / Misc Servers / Zope.exe / ZCLASS.PY < prev    next >
Encoding:
Python Source  |  2000-11-01  |  24.8 KB  |  739 lines

  1. ##############################################################################
  2. # Zope Public License (ZPL) Version 1.0
  3. # -------------------------------------
  4. # Copyright (c) Digital Creations.  All rights reserved.
  5. # This license has been certified as Open Source(tm).
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions are
  8. # met:
  9. # 1. Redistributions in source code must retain the above copyright
  10. #    notice, this list of conditions, and the following disclaimer.
  11. # 2. Redistributions in binary form must reproduce the above copyright
  12. #    notice, this list of conditions, and the following disclaimer in
  13. #    the documentation and/or other materials provided with the
  14. #    distribution.
  15. # 3. Digital Creations requests that attribution be given to Zope
  16. #    in any manner possible. Zope includes a "Powered by Zope"
  17. #    button that is installed by default. While it is not a license
  18. #    violation to remove this button, it is requested that the
  19. #    attribution remain. A significant investment has been put
  20. #    into Zope, and this effort will continue if the Zope community
  21. #    continues to grow. This is one way to assure that growth.
  22. # 4. All advertising materials and documentation mentioning
  23. #    features derived from or use of this software must display
  24. #    the following acknowledgement:
  25. #      "This product includes software developed by Digital Creations
  26. #      for use in the Z Object Publishing Environment
  27. #      (http://www.zope.org/)."
  28. #    In the event that the product being advertised includes an
  29. #    intact Zope distribution (with copyright and license included)
  30. #    then this clause is waived.
  31. # 5. Names associated with Zope or Digital Creations must not be used to
  32. #    endorse or promote products derived from this software without
  33. #    prior written permission from Digital Creations.
  34. # 6. Modified redistributions of any form whatsoever must retain
  35. #    the following acknowledgment:
  36. #      "This product includes software developed by Digital Creations
  37. #      for use in the Z Object Publishing Environment
  38. #      (http://www.zope.org/)."
  39. #    Intact (re-)distributions of any official Zope release do not
  40. #    require an external acknowledgement.
  41. # 7. Modifications are encouraged but must be packaged separately as
  42. #    patches to official Zope releases.  Distributions that do not
  43. #    clearly separate the patches from the original work must be clearly
  44. #    labeled as unofficial distributions.  Modifications which do not
  45. #    carry the name Zope may be packaged in any form, as long as they
  46. #    conform to all of the clauses above.
  47. # Disclaimer
  48. #   THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
  49. #   EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  50. #   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  51. #   PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
  52. #   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  53. #   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  54. #   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  55. #   USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  56. #   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  57. #   OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  58. #   OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  59. #   SUCH DAMAGE.
  60. # This software consists of contributions made by Digital Creations and
  61. # many individuals on behalf of Digital Creations.  Specific
  62. # attributions are listed in the accompanying credits file.
  63. ##############################################################################
  64. """Zope Classes
  65. """
  66. import Globals, string, OFS.SimpleItem, OFS.PropertySheets, Products
  67. import Method, Basic, Property, AccessControl.Role, ts_regex
  68.  
  69. from ZPublisher.mapply import mapply
  70. from ExtensionClass import Base
  71. from App.FactoryDispatcher import FactoryDispatcher
  72. from ComputedAttribute import ComputedAttribute
  73. import OFS.PropertySheets
  74.  
  75. if not hasattr(Products, 'meta_types'):
  76.     Products.meta_types=()
  77.  
  78. if not hasattr(Products, 'meta_classes'):
  79.     Products.meta_classes={}
  80.     Products.meta_class_info={}
  81.  
  82. def createZClassForBase( base_class, pack, nice_name=None, meta_type=None ):
  83.     """
  84.       * Create a ZClass for 'base_class' in 'pack' (before a ProductContext
  85.         is available).  'pack' may be either the module which is to
  86.         contain the ZClass or its 'globals()'.  If 'nice_name' is
  87.         passed, use it as the name for the created class, and create
  88.         the "ugly" '_ZClass_for_...' name as an alias;  otherwise,
  89.         just use the "ugly" name.
  90.  
  91.       * Register the ZClass under its meta_type in the Products registries.
  92.     """
  93.     d                 = {}
  94.     zname             = '_ZClass_for_' + base_class.__name__
  95.  
  96.     if nice_name is None:
  97.         nice_name = zname
  98.  
  99.     exec 'class %s: pass' % nice_name in d
  100.  
  101.     Z                 = d[nice_name]
  102.     Z.propertysheets  = OFS.PropertySheets.PropertySheets()
  103.     Z._zclass_        = base_class
  104.     Z.manage_options  = ()
  105.  
  106.     try:
  107.         Z.__module__  = pack.__name__
  108.         setattr( pack, nice_name, Z )
  109.         setattr( pack, zname, Z )
  110.     except AttributeError: # we might be passed 'globals()'
  111.         Z.__module__      = pack[ '__name__' ]
  112.         pack[ nice_name ] = Z
  113.         pack[ zname ]     = Z
  114.  
  115.     if meta_type is None:
  116.         if hasattr(base_class, 'meta_type'): meta_type=base_class.meta_type
  117.         else:                                meta_type=base_class.__name__
  118.  
  119.     base_module = base_class.__module__
  120.     base_name   = base_class.__name__
  121.         
  122.     key         = "%s/%s" % (base_module, base_name)
  123.  
  124.     if base_module[:9] == 'Products.':
  125.         base_module = string.split( base_module,'.' )[1]
  126.     else:
  127.         base_module = string.split( base_module,'.' )[0]
  128.         
  129.     info="%s: %s" % ( base_module, base_name )
  130.  
  131.     Products.meta_class_info[key] = info # meta_type
  132.     Products.meta_classes[key]    = Z
  133.  
  134.     return Z
  135.  
  136. from OFS.misc_ import p_
  137.  
  138. p_.ZClass_Icon=Globals.ImageFile('class.gif', globals())
  139.  
  140. class PersistentClass(Base):
  141.     def __class_init__(self): pass
  142.  
  143. manage_addZClassForm=Globals.HTMLFile(
  144.     'addZClass', globals(), default_class_='OFS.SimpleItem Item',
  145.     CreateAFactory=1,
  146.     zope_object=1)
  147.  
  148.  
  149. def find_class(ob, name):
  150.     # Walk up the aq hierarchy, looking for a ZClass
  151.     # with the given name.
  152.     while 1:
  153.         if hasattr(ob, name):
  154.             return getattr(ob, name)
  155.         elif hasattr(ob, '_getOb'):
  156.             try:    return ob._getOb(name)
  157.             except: pass
  158.         if hasattr(ob, 'aq_parent'):
  159.             ob=ob.aq_parent
  160.             continue
  161.         raise AttributeError, name
  162.  
  163. def dbVersionEquals(ver):
  164.     # A helper function to isolate db version checking.
  165.     return hasattr(Globals, 'DatabaseVersion') and \
  166.        Globals.DatabaseVersion == ver
  167.  
  168.  
  169. bad_id=ts_regex.compile('[^a-zA-Z0-9_]').search
  170.  
  171. def manage_addZClass(self, id, title='', baseclasses=[],
  172.                      meta_type='', CreateAFactory=0, REQUEST=None,
  173.                      zope_object=0):
  174.     """Add a Z Class
  175.     """
  176.     if bad_id(id) != -1:
  177.         raise 'Bad Request', (
  178.             'The id %s is invalid as a class name.' % id)
  179.     if not meta_type: meta_type=id
  180.  
  181.     r={}
  182.     for data in self.aq_acquire('_getProductRegistryData')('zclasses'):
  183.         r['%(product)s/%(id)s' % data]=data['meta_class']
  184.  
  185.     bases=[]
  186.     for b in baseclasses:
  187.         if Products.meta_classes.has_key(b):
  188.             bases.append(Products.meta_classes[b])
  189.         elif r.has_key(b):
  190.             bases.append(r[b])
  191.         else:
  192.             raise 'Invalid class', b
  193.  
  194.     Z=ZClass(id, title, bases, zope_object=zope_object)
  195.     Z._zclass_.meta_type=meta_type
  196.     self._setObject(id, Z)
  197.  
  198.     if CreateAFactory and meta_type:
  199.         self.manage_addDTMLMethod(
  200.             id+'_addForm', 
  201.             id+' constructor input form', 
  202.             addFormDefault % {'id': id, 'meta_type': meta_type},
  203.             )
  204.         self.manage_addDTMLMethod(
  205.             id+'_add',
  206.             id+' constructor',
  207.             addDefault % {'id': id},
  208.             )
  209.         self.manage_addPermission(
  210.             id+'_add_permission',
  211.             id+' constructor permission',
  212.             'Add %ss' % meta_type 
  213.             )
  214.         self.manage_addPrincipiaFactory(
  215.             id+'_factory',
  216.             id+' factory',
  217.             meta_type,
  218.             id+'_addForm',
  219.             'Add %ss' % meta_type 
  220.             )
  221.  
  222.         Z=self._getOb(id)
  223.         Z.propertysheets.permissions.manage_edit(
  224.             selected=['Add %ss' % id])
  225.         Z.manage_setPermissionMapping(
  226.             permission_names=['Create class instances'],
  227.             class_permissions=['Add %ss' % meta_type]
  228.         ) 
  229.     if REQUEST is not None:
  230.         return self.manage_main(self,REQUEST, update_menu=1)
  231.  
  232. class Template:
  233.     _p_oid=_p_jar=__module__=None
  234.     _p_changed=0
  235.     icon=''
  236.  
  237. def PersistentClassDict(doc=None, meta_type=None):
  238.         # Build new class dict
  239.         dict={}
  240.         dict.update(Template.__dict__)
  241.         if meta_type is not None:
  242.             dict['meta_type']=dict['__doc__']=meta_type
  243.         if doc is not None:
  244.             dict['__doc__']=doc
  245.         return dict
  246.  
  247. _marker=[]
  248. class ZClass(OFS.SimpleItem.SimpleItem):
  249.     """Zope Class
  250.     """
  251.     meta_type="Z Class"
  252.     icon="p_/ZClass_Icon"
  253.     instance__meta_type='instance'
  254.     instance__icon=''
  255.     __propsets__=()
  256.     isPrincipiaFolderish=1
  257.  
  258.     __ac_permissions__=(
  259.         ('Create class instances',
  260.          ('', '__call__', 'index_html', 'createInObjectManager')),
  261.         )
  262.  
  263.     def __init__(self, id, title, bases, zope_object=1):
  264.         """Build a Zope class
  265.  
  266.         A Zope class is *really* a meta-class that manages an
  267.         actual extension class that is instantiated to create instances.
  268.         """
  269.         self.id=id
  270.         self.title=title
  271.         
  272.         # Set up base classes for new class, the meta class prop
  273.         # sheet and the class(/instance) prop sheet.
  274.         base_classes=[PersistentClass]
  275.         zsheets_base_classes=[PersistentClass]
  276.         isheets_base_classes=[PersistentClass]
  277.         zbases=[ZStandardSheets]
  278.         for z in bases:
  279.             base_classes.append(z._zclass_)
  280.             zbases.append(z)
  281.             try: zsheets_base_classes.append(z.propertysheets.__class__)
  282.             except AttributeError: pass
  283.             try:
  284.                 psc=z._zclass_.propertysheets.__class__
  285.                 if getattr(psc,
  286.                            '_implements_the_notional'
  287.                            '_subclassable_propertysheet'
  288.                            '_class_interface',
  289.                            0):
  290.                     isheets_base_classes.append(psc)
  291.             except AttributeError: pass
  292.  
  293.         if zope_object:
  294.             base_classes.append(OFS.SimpleItem.SimpleItem)
  295.             
  296.         zsheets_base_classes.append(ZClassSheets)
  297.         isheets_base_classes.append(Property.ZInstanceSheets)
  298.  
  299.         # Create the meta-class property sheet
  300.         zsheets_class=type(PersistentClass)(
  301.             id+'_ZPropertySheetsClass',
  302.             tuple(zsheets_base_classes)+(Globals.Persistent,),
  303.             PersistentClassDict(id+'_ZPropertySheetsClass'))
  304.         self.propertysheets=sheets=zsheets_class()
  305.  
  306.         # Create the class
  307.         self._zclass_=c=type(PersistentClass)(
  308.             id, tuple(base_classes),
  309.             PersistentClassDict(title or id))
  310.         c.__ac_permissions__=()
  311.  
  312.         # Copy manage options
  313.         if zope_object:
  314.             options=[]
  315.             for option in c.manage_options:
  316.                 copy={}
  317.                 copy.update(option)
  318.                 options.append(copy)
  319.             c.manage_options=tuple(options)
  320.         
  321.         # Create the class(/instance) prop sheet *class*
  322.         isheets_class=type(PersistentClass)(
  323.             id+'_PropertySheetsClass',
  324.             tuple(isheets_base_classes),
  325.             PersistentClassDict(id+' Property Sheets'))        
  326.  
  327.         # Record the class property sheet class in the meta-class so
  328.         # that we can manage it:
  329.         self._zclass_propertysheets_class=isheets_class
  330.         
  331.         # Finally create the new classes propertysheets by instantiating the
  332.         # propertysheets class.
  333.         c.propertysheets=isheets_class()
  334.  
  335.         # Save base meta-classes:
  336.         self._zbases=zbases
  337.  
  338.     def cb_isCopyable(self):
  339.         pass # for now, we don't allow ZClasses to be copied.
  340.     cb_isMovable=cb_isCopyable
  341.  
  342.     def _setBasesHoldOnToYourButts(self, bases):
  343.         # Eeeek
  344.         copy=self.__class__(self.id, self.title, bases)
  345.  
  346.         copy._zclass_.__dict__.update(
  347.             self._zclass_.__dict__)
  348.         get_transaction().register(
  349.             copy._zclass_)
  350.         self._p_jar.exchange(self._zclass_, copy._zclass_)
  351.         self._zclass_=copy._zclass_
  352.  
  353.         copy._zclass_propertysheets_class.__dict__.update(
  354.             self._zclass_propertysheets_class.__dict__)
  355.         get_transaction().register(
  356.             copy._zclass_propertysheets_class)
  357.         self._p_jar.exchange(self._zclass_propertysheets_class,
  358.                              copy._zclass_propertysheets_class)
  359.         self._zclass_propertysheets_class=copy._zclass_propertysheets_class
  360.  
  361.         if hasattr(self.propertysheets.__class__, '_p_oid'):
  362.             copy.propertysheets.__class__.__dict__.update(
  363.                 self.propertysheets.__class__.__dict__)
  364.             get_transaction().register(
  365.                 copy.propertysheets.__class__)
  366.             self._p_jar.exchange(self.propertysheets.__class__,
  367.                                  copy.propertysheets.__class__)
  368.  
  369.         self._zbases=copy._zbases
  370.  
  371.     def _new_class_id(self):
  372.         import md5, base64, time
  373.  
  374.         id=md5.new()
  375.         id.update(self.absolute_url())
  376.         id.update(str(time.time()))
  377.         id=id.digest()
  378.         id=string.strip(base64.encodestring(id))
  379.  
  380.         return '*'+id
  381.  
  382.     def changeClassId(self, newid=None):
  383.         if not dbVersionEquals('3'):
  384.             return
  385.         if newid is None: newid=self._new_class_id()
  386.         self._unregister()
  387.         if newid:
  388.             if not newid[:1] == '*': newid='*'+newid
  389.             self.setClassAttr('__module__', newid)
  390.             self._register()
  391.  
  392.     def _waaa_getJar(self):
  393.         # Waaa, we need our jar to register, but we may not have one yet when
  394.         # we need to register, so we'll walk our acquisition tree looking
  395.         # for one.
  396.         jar=None
  397.         while 1:
  398.             if hasattr(self, '_p_jar'):
  399.                 jar=self._p_jar
  400.             if jar is not None:
  401.                 return jar
  402.             if not hasattr(self, 'aq_parent'):
  403.                 return jar
  404.             self=self.aq_parent
  405.  
  406.  
  407.     def _register(self):
  408.  
  409.         # Register the global id of the managed class:
  410.         z=self._zclass_
  411.         class_id=z.__module__
  412.         if not class_id: return
  413.  
  414.         jar=self._waaa_getJar()
  415.         globals=jar.root()['ZGlobals']
  416.         if globals.has_key(class_id):
  417.             raise 'Duplicate Class Ids'
  418.  
  419.         globals[class_id]=z
  420.  
  421.         product=self.aq_inner.aq_parent.zclass_product_name()
  422.  
  423.         # Register self as a ZClass:
  424.         self.aq_acquire('_manage_add_product_data')(
  425.             'zclasses',
  426.             product=product,
  427.             id=self.id,
  428.             meta_type=z.meta_type or '',
  429.             meta_class=self,
  430.             )
  431.  
  432.     def _unregister(self):
  433.  
  434.         # Unregister the global id of the managed class:
  435.         class_id=self._zclass_.__module__
  436.         if not class_id: return
  437.         globals=self._p_jar.root()['ZGlobals']
  438.         if globals.has_key(class_id):
  439.             del globals[class_id]
  440.  
  441.         product=self.aq_inner.aq_parent.zclass_product_name()
  442.  
  443.         # Unregister self as a ZClass:
  444.         self.aq_acquire('_manage_remove_product_data')(
  445.             'zclasses',
  446.             product=product,
  447.             id=self.id,
  448.             )
  449.  
  450.     def zclass_product_name(self):
  451.         product=self.aq_inner.aq_parent.zclass_product_name()
  452.         return "%s/%s" % (product, self.id)
  453.  
  454.     def manage_afterClone(self, item):
  455.         self.setClassAttr('__module__', None)
  456.         self.propertysheets.methods.manage_afterClone(item)
  457.         
  458.     def manage_afterAdd(self, item, container):
  459.         if not dbVersionEquals('3'):
  460.             return
  461.         if not self._zclass_.__module__:
  462.             self.setClassAttr('__module__', self._new_class_id())
  463.         self._register()
  464.         self.propertysheets.methods.manage_afterAdd(item, container)
  465.  
  466.     def manage_beforeDelete(self, item, container):
  467.         if not dbVersionEquals('3'):
  468.             return
  469.         self._unregister()
  470.         self.propertysheets.methods.manage_beforeDelete(item, container)
  471.  
  472.     def manage_options(self):
  473.         r=[]
  474.         d={}
  475.         have=d.has_key
  476.         for z in self._zbases:
  477.             for o in z.manage_options:                
  478.                 label=o['label']
  479.                 if have(label): continue
  480.                 d[label]=1
  481.                 r.append(o)
  482.         return r
  483.  
  484.     manage_options=ComputedAttribute(manage_options)
  485.  
  486.     def createInObjectManager(self, id, REQUEST, RESPONSE=None):
  487.         """
  488.         Create Z instance. If called with a RESPONSE,
  489.         the RESPONSE will be redirected to the management
  490.         screen of the new instance's parent Folder. Otherwise,
  491.         the instance will be returned.
  492.         """
  493.         i=mapply(self._zclass_, (), REQUEST)
  494.         i._setId(id)
  495.         folder=durl=None
  496.         if hasattr(self, 'Destination'):
  497.             d=self.Destination
  498.             if d.im_self.__class__ is FactoryDispatcher:
  499.                 folder=d()
  500.         if folder is None: folder=self.aq_parent
  501.         if not hasattr(folder,'_setObject'):
  502.             folder=folder.aq_parent
  503.  
  504.         folder._setObject(id, i)
  505.  
  506.         if RESPONSE is not None:
  507.             try: durl=self.DestinationURL()
  508.             except: durl=REQUEST['URL3']
  509.             RESPONSE.redirect(durl+'/manage_workspace')
  510.         else:
  511.             return folder._getOb(id)
  512.         
  513.     index_html=createInObjectManager
  514.  
  515.     def fromRequest(self, id=None, REQUEST={}):
  516.         i=mapply(self._zclass_, (), REQUEST)
  517.         if id is not None and (not hasattr(i, 'id') or not i.id): i.id=id
  518.  
  519.         return i
  520.         
  521.     def __call__(self, *args, **kw):
  522.         return apply(self._zclass_, args, kw)
  523.  
  524.     def zclass_candidate_view_actions(self):
  525.         r={}
  526.  
  527.         zclass=self._zclass_
  528.         # Step one, look at all of the methods.
  529.         # We can cheat (hee hee) and and look in the _zclass_
  530.         # dict for wrapped objects.
  531.         for id in Method.findMethodIds(zclass):
  532.             r[id]=1
  533.  
  534.         # OK, now lets check out the inherited views:
  535.         findActions(zclass, r)
  536.  
  537.         # OK, now add our property sheets.
  538.         for id in self.propertysheets.common.objectIds():
  539.             r['propertysheets/%s/manage' % id]=1
  540.  
  541.         r=r.keys()
  542.         r.sort()
  543.         return r
  544.  
  545.     def getClassAttr(self, name, default=_marker, inherit=0):
  546.         if default is _marker:
  547.             if inherit: return getattr(self._zclass_, name)
  548.             else: return self._zclass_.__dict__[name]
  549.         try:
  550.             if inherit: return getattr(self._zclass_, name)
  551.             else: return self._zclass_.__dict__[name]
  552.         except: return default
  553.  
  554.     def setClassAttr(self, name, value):
  555.         c=self._zclass_
  556.         setattr(c, name, value)
  557.         if not c._p_changed:
  558.             get_transaction().register(c)
  559.             c._p_changed=1
  560.  
  561.     def delClassAttr(self, name):
  562.         c=self._zclass_
  563.         delattr(c, name)
  564.         if not c._p_changed:
  565.             get_transaction().register(c)
  566.             c._p_changed=1
  567.  
  568.     def classDefinedPermissions(self):
  569.         c=self._zclass_
  570.         r=[]
  571.         a=r.append
  572.         for p in c.__ac_permissions__: a(p[0])
  573.         r.sort()
  574.         return r
  575.  
  576.     def classInheritedPermissions(self):
  577.         c=self._zclass_
  578.         d={}
  579.         for p in c.__ac_permissions__: d[p[0]]=None
  580.         r=[]
  581.         a=r.append
  582.         for p in AccessControl.Role.gather_permissions(c, [], d): a(p[0])
  583.         r.sort()
  584.         return r
  585.  
  586.     def classDefinedAndInheritedPermissions(self):
  587.         return (self.classDefinedPermissions()+
  588.                 self.classInheritedPermissions())
  589.  
  590.     def ziconImage(self, REQUEST, RESPONSE):
  591.         "Display a class icon"
  592.         return self._zclass_.ziconImage.index_html(REQUEST, RESPONSE)
  593.  
  594.     ziconImage__roles__=None
  595.  
  596.     def tpValues(self):
  597.         return self.propertysheets.common, self.propertysheets.methods
  598.  
  599.     def ZClassBaseClassNames(self):
  600.         r=[]
  601.         for c in self._zbases:
  602.             if hasattr(c, 'id'): r.append(c.id)
  603.             elif hasattr(c, '__name__'): r.append(c.__name__)
  604.  
  605.         return r
  606.  
  607.     def _getZClass(self): return self
  608.             
  609. class ZClassSheets(OFS.PropertySheets.PropertySheets):
  610.     "Manage a collection of property sheets that provide ZClass management"
  611.  
  612.     #isPrincipiaFolderish=1
  613.     #def tpValues(self): return self.methods, self.common
  614.     #def tpURL(self): return 'propertysheets'
  615.     def manage_workspace(self, URL2):
  616.         "Emulate standard interface for use with navigation"
  617.         raise 'Redirect', URL2+'/manage_workspace'
  618.  
  619.     views       = Basic.ZClassViewsSheet('views')
  620.     basic       = Basic.ZClassBasicSheet('basic')
  621.     permissions = Basic.ZClassPermissionsSheet('permissions')
  622.  
  623.     def __init__(self):
  624.         self.methods=Method.ZClassMethodsSheet('methods')
  625.         self.common=Property.ZInstanceSheetsSheet('common')
  626.  
  627.  
  628. class ZObject:
  629.  
  630.     manage_options=(
  631.         {'label': 'Methods', 'action' :'propertysheets/methods/manage',
  632.          'help':('OFSP','ZClass_Methods.stx')},        
  633.         {'label': 'Basic', 'action' :'propertysheets/basic/manage',
  634.          'help':('OFSP','ZClass_Basic.stx')},          
  635.         {'label': 'Views', 'action' :'propertysheets/views/manage',
  636.          'help':('OFSP','ZClass_Views.stx')},          
  637.         {'label': 'Property Sheets', 'action' :'propertysheets/common/manage',
  638.          'help':('OFSP','ZClass_Property-Sheets.stx')},        
  639.         {'label': 'Permissions',
  640.          'action' :'propertysheets/permissions/manage',
  641.          'help':('OFSP','ZClass_Permissions.stx')},     
  642.         {'label': 'Define Permissions', 'action' :'manage_access',  
  643.          'help':('OFSP','Security_Define-Permissions.stx')},        
  644.         )
  645.  
  646.     
  647. ZStandardSheets=ZObject
  648.  
  649. def findActions(klass, found):
  650.     for b in klass.__bases__:
  651.         try:
  652.             for d in b.manage_options:
  653.                 found[d['action']]=1
  654.             findActions(b, found)
  655.         except: pass
  656.  
  657. addFormDefault="""<HTML> 
  658. <HEAD><TITLE>Add %(meta_type)s</TITLE></HEAD> 
  659. <BODY BGCOLOR="#FFFFFF" LINK="#000099" VLINK="#555555"> 
  660. <H2>Add %(meta_type)s</H2> 
  661. <form action="%(id)s_add"><table> 
  662. <tr><th>Id</th> 
  663.     <td><input type=text name=id></td> 
  664. </tr> 
  665. <tr><td></td><td><input type=submit value=" Add "></td></tr> 
  666. </table></form> 
  667. </body></html> 
  668. """
  669.  
  670. addDefault="""<HTML>
  671. <HEAD><TITLE>Add %(id)s</TITLE></HEAD>
  672. <BODY BGCOLOR="#FFFFFF" LINK="#000099" VLINK="#555555">
  673.  
  674. <dtml-comment> We add the new object by calling the class in
  675.                 a with tag.  Not only does this get the thing
  676.                 added, it adds the new thing's attributes to
  677.                 the DTML name space, so we can call methods
  678.                 to initialize the object.
  679. </dtml-comment>
  680.  
  681. <dtml-with "%(id)s.createInObjectManager(REQUEST['id'], REQUEST)">
  682.  
  683.   <dtml-comment>
  684.  
  685.      You can add code that modifies the new instance here.
  686.  
  687.      For example, if you have a property sheet that you want to update
  688.      from form values, you can call it here:
  689.  
  690.        <dtml-call "propertysheets.Basic.manage_editProperties(
  691.                   REQUEST)">
  692.  
  693.   </dtml-comment>
  694.  
  695. </dtml-with>
  696.  
  697. <dtml-comment> Now we need to return something.  We do this via
  698.                 a redirect so that the URL is correct.
  699.  
  700.                 Unfortunately, the way we do this depends on
  701.                 whether we live in a product or in a class.
  702.                 If we live in a product, we need to use DestinationURL
  703.                 to decide where to go. If we live in a class,
  704.                 DestinationURL won't be available, so we use URL2.
  705. </dtml-comment>
  706. <dtml-if DestinationURL>
  707.  
  708.  <dtml-call "RESPONSE.redirect(
  709.        DestinationURL+'/manage_workspace')">
  710.  
  711. <dtml-else>
  712.  
  713.     <dtml-call "RESPONSE.redirect(
  714.            URL2+'/manage_workspace')">
  715. </dtml-if>
  716. </body></html>
  717. """
  718.